<?php

namespace App\Modules\Activity\Controllers;

use App\Lib\Utilities;
use App\Modules\Activity\Services\ActivityService;
use App\Modules\Activity\Validators\ActivityControllerValidator;
use App\Modules\System\Repositories\DictionaryRepository;
use Flower\Core\Http\BaseController;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Flower\Core\Repository\Exceptions\ValidatorException;

class ActivityController extends BaseController
{

    private $activityService;

    public function __construct(ActivityService $activityService)
    {
        $this->activityService = $activityService;
    }

    public function getRules()
    {
        return ActivityControllerValidator::validator();
    }

    /**
     * 发布店铺活动
     * @param Request $request
     * @return mixed
     */
    public function createActivity(Request $request)
    {

        $store_id = $request->input('store_id');
        $title = $request->input('title');
        $playbill = $request->input('playbill');
        $content = $request->input('content');
        $expire = $request->input('expire');
        $activity = $this->activityService->createActivity($store_id,$title,$playbill,$content,$expire);


        $data = [
            'activity_id' => $activity->id
        ];

        return $this->display($data, '查询成功');

    }

    /**
     * 编辑门店活动
     * @param Request $request
     * @return mixed
     */
    public function editActivity(Request $request)
    {

        $activity_id = $request->input('activity_id');
        $title = $request->input('title');
        $playbill = $request->input('playbill');
        $content = $request->input('content');
        $this->activityService->editActivity($activity_id, $title, $playbill, $content);

        return $this->success('修改成功');

    }

    /**
     * 删除门店活动
     * @param Request $request
     * @return mixed
     */
    public function delActivity(Request $request)
    {
        $activity_id = $request->input('activity_id');
        $this->activityService->delActivity($activity_id);

        return $this->success('删除成功');

    }

    /**
     * 获取门店活动列表
     * @param Request $request
     * @return mixed
     */
    public function getActivityListPage(Request $request)
    {

        $store_id = $request->input('store_id');
        $pageSize = $request->input('pageSize',10);
        $activity_list = $this->activityService->getActivityListPage($store_id,$pageSize);

        return $this->display($activity_list, '返回成功');

    }

    /**
     * 小程序端获取公告列表
     * @param Request $request
     * @return mixed
     */
    public function getActivityListPageWx(Request $request)
    {

        $store_id = $request->input('store_id');
        $pageSize = $request->input('pageSize',10);
        $activity_list = $this->activityService->getActivityListPageWx($store_id,$pageSize);

        return $this->display($activity_list, '返回成功');

    }

    /**
     * 获取公告详情
     * @param Request $request
     * @return mixed
     * @throws \App\Exceptions\AllValidatorException
     */
    public function getActivity(Request $request)
    {
        $activity_id = $request->input('activity_id');
        $data = $this->activityService->getActivity($activity_id);
        return $this->display($data, '查询成功');
    }

    /**
     * 获取活动类型
     * @param Request $request
     * @return mixed
     */
    public function getEnrollActivityList(Request $request)
    {
        $result = [
            [
                'id' => 1,
                'title' => '活动公告',
                'condition' => '无门槛限制',
                'is_allow' => 1,
            ]
        ];
        $data = [
            'items' => $result,
            'nextPageToken' => 2,
            'prevPageToken' => 0,
            'requestCount' => 1,
            'totalResults' => 1,
            'currPageToken' => 1,
        ];
        return $this->display($data, '查询成功');
    }

    /**
     * 获取活动海报
     * @param Request $request
     */
    public function getActivityPlaybill(Request $request)
    {
        $data = $this->activityService->getActivityPlaybill();
        return $this->display($data, '查询成功');
    }
}
